package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateBuildingDialog;
import pl.prv.polanie.client.dto.CSBuildingDTO;
import pl.prv.polanie.client.dto.CSVBuildingDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableBuildings;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class BuildingsList extends ObjectsList {

	TableBuildings tableBuildings= new TableBuildings(this);
	
	public BuildingsList() {
		
		CSBuildingDTO[] ls = Cache.getAllBuildings();
		//BuildingDTO[] ats = Cache.getAllBuildings();
		
		add(tableBuildings);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSBuildingDTO cs = ls[i];
			CSVBuildingDTO csv = ViewDataProvider.getCSVBuilding(cs);
			
			tableBuildings.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateBuildingDialog catd = new CreateBuildingDialog(BuildingsList.this, null); 
				catd.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableBuildings.removeSelectedBuildingFromTable();
				removeSelectedRecordButton.setEnabled(false);
			}
		});
		
		setupButtons();
	}

	
	public void addCSBuilding(CSBuildingDTO csBuilding) {
//		CSVLecturerDTO csv = ViewDataProvider.getCSVLecturer(csLecturer);
		
		tableBuildings.saveOrUpdateBuildingInTable(csBuilding);
//		tableBuildings.addRow(csLecturer, csv);
	}
	
	public void removeSelectdCSLecturer() {
		tableBuildings.removeSelectedBuildingFromTable();
	}
	

}
